package com.guigu.www.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.pojo.*;
import com.guigu.www.service.MDesignProcedureDetailsService;
import com.guigu.www.service.MDesignProcedureService;
import com.guigu.www.service.MDesingProndureModuleService;
import org.apache.commons.collections.bag.SynchronizedSortedBag;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class MDesignProcedureDetailsController {
    //产品生产工序明细
    @Autowired
    MDesignProcedureDetailsService mdpdservice;

    //产品生产工序
    @Autowired
    MDesignProcedureService mDesignProcedureService;

    //id查询dq确定
    @GetMapping("querymdpdservicebyidshow.action/{id}")
    public DesignProcedureDetails querymdpdservicebyidshow(@PathVariable int id)
    {
        return mdpdservice.getById(id);
    }

    //c
    //更据父id查询
    @RequestMapping("querydesignProcedureDetails.action/{parentid}")
    public PageVo<DesignProcedureDetails> querydesignProcedureDetailsjk(DesignProcedureDetails designProcedureDetails,
                                                                        @PathVariable Integer parentid,
                                                                        @RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
                                                                        @RequestParam(value = "pagesize", defaultValue = "5") int pagesize) {
        QueryWrapper<DesignProcedureDetails> queryWrapper = new QueryWrapper<DesignProcedureDetails>();
        DesignProcedure d = mDesignProcedureService.getById(parentid);

        queryWrapper.eq("PARENT_ID", d.getId());

        Page<DesignProcedureDetails> page = mdpdservice.page(new Page<DesignProcedureDetails>(pagenum, pagesize), queryWrapper);

        PageVo<DesignProcedureDetails> pageVo = new PageVo<DesignProcedureDetails>();
        pageVo.setRows(page.getRecords());
        pageVo.setTotal(page.getTotal());

        return pageVo;
    }


    //删除明细表
    @RequestMapping("delmddc.action/{id}")
    public Map delmddc(@PathVariable Integer id
    ) {
        Map map = new HashMap();
        boolean f= mdpdservice.removeById(id);
        if (f) {
            map.put("msg", "删除成功");
        } else {
            map.put("msg", "删除失败");
        }
        return map;
    }


    //del父id查询
    @RequestMapping("deldesignProcedureDetails.action/{parentid}")
    public PageVo<DesignProcedureDetails> deldesignProcedureDetails(DesignProcedureDetails designProcedureDetails,
                                                                        @PathVariable Integer parentid,
                                                                        @RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
                                                                        @RequestParam(value = "pagesize", defaultValue = "5") int pagesize) {
        QueryWrapper<DesignProcedureDetails> queryWrapper = new QueryWrapper<DesignProcedureDetails>();
        DesignProcedure d = mDesignProcedureService.getById(parentid);
        mDesignProcedureService.removeById(d.getId());

        Page<DesignProcedureDetails> page = mdpdservice.page(new Page<DesignProcedureDetails>(pagenum, pagesize), queryWrapper);
        PageVo<DesignProcedureDetails> pageVo = new PageVo<DesignProcedureDetails>();
        pageVo.setRows(page.getRecords());
        pageVo.setTotal(page.getTotal());

        return pageVo;
    }

}
